<?php

// $Id: feature.inc 24 2010-11-11 07:33:55Z mjohnson60@gmail.com $
//
// $Author: mjohnson60@gmail.com $
// $Date: 2010-10-29 07:27:52 -0400 (Fri, 29 Oct 2010) $
//
// $Rev: 16 $
//


class Feature extends DBObject
{
	var $fid = 0;
	
	var $description = 'Please enter a description.';
	var $details = 'Please enter details.';

	/**
	 * Feature::Feature()
	 * 
	 * @return
	 */
	public function Feature($data = NULL)
	{
		$this->table = 'feature';
		
		$this->id_name = 'fid';
		
		$this->fields = array(
			'description' => "'%s'", 'details' => "'%s'"
		);
		
		parent::DBObject($data);
	}

	/**
	 * Feature::schema()
	 * 
	 * @return
	 */
	public static function schema()
	{
		return 'CREATE TABLE IF NOT EXISTS `feature` (
    			  `fid` int(10) unsigned NOT NULL AUTO_INCREMENT,
    			  `description` varchar(255) DEFAULT NULL,
    			  `details` text,
    			  PRIMARY KEY (`fid`),
    			  UNIQUE KEY `fid_UNIQUE` (`fid`)
    			) ENGINE=InnoDB DEFAULT CHARSET=utf8';
	}

	/**
	 * Feature::install()
	 * 
	 * @return
	 */
	public static function install()
	{
		db_query('DROP TABLE IF EXISTS feature');
		$result = db_query(Feature::schema());
		
		if ($result !== FALSE)
		{
			db_query("INSERT INTO feature (description, details) VALUES ('Please enter a description.', 'Please enter details.')");
			db_query("UPDATE feature SET fid=0 WHERE description='Please enter a description.'");
			db_query('ALTER TABLE feature AUTO_INCREMENT=1');
			
			system_set_message('The <code>features</code> table was successfully created.');
			
			return TRUE;
		}
		else
		{
			system_set_message('The <code>features</code> table was not created.');
			
			return FALSE;
		}
	}

	/**
	 * Feature::uninstall()
	 * 
	 * @return
	 */
	public static function uninstall()
	{
		$result = db_query('DROP TABLE IF EXISTS feature');
		if ($result !== FALSE)
		{
			system_set_message('The <code>feature</code> table was successfully removed.');
			
			return TRUE;
		}
		else
		{
			system_set_message('The <code>feature</code> table was not removed.');
			
			return FALSE;
		}
	}
}
